<?php
/******************************************
 * Author: <YOUR NAME HERE>
 * Description: <YOUR DESCRIPTION HERE>
 ******************************************/
class Recepti extends CustomSecurity { 

	var $db; 
	var $id;
	var $recepta_ime;
	var $description;

	function Recepti($db){ 
    }

	/***********************************
 	 * Add:         Allows the insertion of values into the Table.
 	 * Parameters:  $id, $recepta_ime, $description
 	 * Return:      (Boolean) True - Successfully Inserted | False - Error
 	 ************************************/
	function add($recepta_ime, $description, $category){ 

		escape_string($recepta_ime);
		escape_string($description);
		escape_string($category);

		$statement = "INSERT INTO recepti (recepta_ime, description, category, userId) VALUES ('$recepta_ime', '$description', '$category', '".$_SESSION['user_id']."');";
		$results   = mysql_query($statement);

		if($results){
			return mysql_insert_id(mysql_connection);
		}else{
			return -1;
		}

	}//End add()


	/***********************************
 	 * Remove:      Allows for the removal of record from the database.
 	 * Parameters:  (String)Primary Key Column Name | (Int) Primary Key Value
 	 * Return:      (Boolean) True - Successfully Removed | False - Error
 	 ************************************/
	function remove($primaryKeyValue){ 

		escape_string($primaryKeyValue);

		$statement = "DELETE FROM recepti WHERE id = '$primaryKeyValue'";
		$results   = mysql_query($statement);
		if($results){
			return true;
		}else{
			return false;
		}

	}//End remove()


	/***********************************
 	 * Update:      Allows for the update of a record from the database.
 	 * Parameters:  (String)Primary Key Column Name | (Int) Primary Key Value | (String) Column Name To Update | (String) New Value
 	 * Return:      (Boolean) True - Successfully Updated | False - Error
 	 ************************************/
	function update($primaryKeyValue, $ime, $text, $category){ 

		escape_string($primaryKeyValue);
		escape_string($ime);
		escape_string($text);
		escape_string($category);
		
		$statement = "UPDATE recepti SET recepta_ime = '$ime', description = '$text', category = '$category' WHERE id = '$primaryKeyValue'";
		$results   = mysql_query($statement);
		if($results){
			return $primaryKeyValue;
		}else{
			return false;
		}

	}//End update()


	/***********************************
 	 * GetAll:       Returns all the records in the database.
 	 * Parameters:   NA
 	 * Return:      (MultiDimensional-Array)String
 	 ************************************/
	function getAll(){ 

		$statement = "SELECT id, recepta_ime, description, category, userId FROM recepti";
		$results   = mysql_query($statement);
		
		$tokens[0] = 'id';
		$tokens[1] = 'recepta_ime';
		$tokens[2] = 'description';
		$tokens[3] = 'category';
		$tokens[4] = 'userId';
		
		return transformResults($results, $tokens);

	}//End getAll()
	
	function get($category){ 

		$statement = "SELECT id, recepta_ime, description, category, userId FROM recepti WHERE category='$category'";
		$results   = mysql_query($statement);
		$tokens[0] = 'id';
		$tokens[1] = 'recepta_ime';
		$tokens[2] = 'description';
		$tokens[3] = 'category';
		$tokens[4] = 'userId';
		
		return transformResults($results, $tokens);

	}//End getAll()

	
	/***********************************
 	 * GetAll:       Returns all the records in the database.
 	 * Parameters:   NA
 	 * Return:      (MultiDimensional-Array)String
 	 ************************************/
	function getAllMine(){ 

		$statement = "SELECT id, recepta_ime, description, category FROM recepti WHERE userId=".$_SESSION['user_id'];
		$results   = mysql_query($statement);
		
		$tokens[0] = 'id';
		$tokens[1] = 'recepta_ime';
		$tokens[2] = 'description';
		$tokens[3] = 'category';
		
		return transformResults($results, $tokens);

	}//End getAll()
	

	/***********************************
 	 * GetObject:   Returns a specific record form the batabase.
 	 * Parameters:  (Int) Primary Key Value
 	 * Return:      (Array)String
 	 ************************************/
	function getObject($primaryKeyValue){ 

		escape_string($primaryKeyValue);

		$statement = "SELECT id, recepta_ime, description, category, userId FROM recepti WHERE id = '".$primaryKeyValue."'";
		$results   = mysql_query($statement);

		$tokens[0] = 'id';
		$tokens[1] = 'recepta_ime';
		$tokens[2] = 'description';
		$tokens[3] = 'category';
		$tokens[4] = 'userId';
		
		return transformResults($results, $tokens);

	}//End getObject()


}//End Class recepti
?>